<template>
    <div class="app-container">
        <el-form ref="elFormSetting" :model="formSettingData" :rules="rules" size="medium" label-width="120px">
            <el-form-item label="上级国标地址" prop="upper_host">
                <el-input
                v-model="formSettingData.upper_host"
                placeholder="请输入上级国标服务器地址"
                :maxlength="256"
                show-word-limit
                clearable
                prefix-icon="el-icon-mobile"
                :style="{width: '100%'}"
                />
            </el-form-item>
            <el-form-item label="上级国标端口" prop="upper_port">
                <el-input
                v-model="formSettingData.upper_port"
                placeholder="请输入上级国标服务器端口"
                clearable
                :style="{width: '100%'}"
                />
            </el-form-item>
            <el-form-item label="上级国标域" prop="upper_realm">
                <el-input
                v-model="formSettingData.upper_realm"
                placeholder="请输入上级国标服务器域"
                clearable
                :style="{width: '100%'}"
                />
            </el-form-item>
            <el-form-item size="large">
                <el-button type="primary" :loading="loading" @click="submitForm">提交</el-button>
                <el-button @click="resetForm">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import { load } from '@/api/setting'
export default {
  name: 'Setting',
  components: {},
  props: [],
  data() {
    return {
      formSettingData: {
        upper_host: undefined,
        upper_port: undefined,
        upper_realm: undefined,
        upper_password: undefined,
        keep_alive_second: 60
      },
      loading: false,
      rules: {
        upper_host: [{ required: true, message: '请输入信令服务器地址', trigger: 'blur' }],
        upper_port: [{ required: true, message: '请输入信令服务端口', trigger: 'blur' }],
        upper_realm: [{ required: true, message: '请输入服务器域', trigger: 'blur' }],
        upper_password: [{ required: true, message: '请输入验证密码', trigger: 'blur' }],
        keep_alive_second: [{ required: true, message: '请输入心跳时间', trigger: 'blur' }]
      }
    }
  },
  computed: {},
  watch: {},
  created() {
    this.fetchData()
  },
  mounted() {},
  methods: {
    fetchData() {
      load().then(ret => {
        console.log('ret.data', ret.data)
        this.formSettingData = ret.data
      })
    },
    submitForm() {
      this.$refs['elFormSetting'].validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('setting/cascadeupsave', this.formSettingData).then(() => {
            // this.$router.push({ path: this.redirect || '/' })
            this.loading = false
          }).catch((err) => {
            console.error(err)
            this.loading = false
          })
        } else {
          this.loading = false
        }
      })
    },
    resetForm() {
      this.$refs['elFormSetting'].resetFields()
    }
  }
}
</script>

<style>
</style>